package online.hxstart.code.concurrent.chapter07;

import java.util.concurrent.TimeUnit;

/**
 * @author huxing
 * @date 19-5-31 星期五 下午9:05
 * @describe
 */
public class ThreadHook {

  public static void main(String[] args) {
    //
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                () -> {
                  try {
                    System.out.println("The hook thread 1 is running.");
                    TimeUnit.SECONDS.sleep(1);
                  } catch (InterruptedException e) {
                    e.printStackTrace();
                  }
                  System.out.println("The hook thread 1 will exit");
                }));

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                () -> {
                  try {
                    System.out.println("The hook thread 2 is running.");
                    TimeUnit.SECONDS.sleep(1);
                  } catch (InterruptedException e) {
                    e.printStackTrace();
                  }
                  System.out.println("The hook thread 1 will exit");
                }));
    System.out.println("The program will is stopping");

  }
}
